//
//  HJForwardCell.swift
//  HJWeiBo
//
//  Created by 黄珏 on 15/11/2.
//  Copyright © 2015年 黄珏. All rights reserved.
//

import UIKit

class HJForwardCell: HJStatusCell {
    override var status: HJStatus? {
        didSet {
            let name = status?.retweeted_status?.user?.name
            let text = status?.retweeted_status?.text 
            forwardLabel.text = "@\(name):" + "\(text)"
        }
    }
    override func prepareUI() {
        super.prepareUI()
        contentView.insertSubview(bkgButton, belowSubview: pictureView)
        contentView.addSubview(forwardLabel)
        // 添加约束
        // 背景
        // 左上角约束
        bkgButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -8, y: 8))
        // 右下角
        bkgButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        // 被转发微博内容label
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: bkgButton, size: nil, offset: CGPoint(x: 8, y: 8))
        // 宽度约束
        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))
        
        // 配图的约束
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 0, height: 0), offset: CGPoint(x: 0, y: 8))
        
        // 获取配图的宽高约束
        pictureViewHeightCon = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        pictureViewWidthCon = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
    }
//    MARK: 懒加载
     lazy var forwardLabel: UILabel = {
       let label = UILabel()
        label.numberOfLines = 0
        return label
    }()
     lazy var bkgButton: UIButton = {
        let button = UIButton()
        button.backgroundColor = UIColor(white: 0.9, alpha: 1)
        return button
    }()
}
